export function generateCaptcha() {
  const width = 150
  const height = 40
  const padding = 25
  const charSpacing = 25
  const verticalOffset = 25

  // 生成随机验证码
  const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  let code = ''
  for (let i = 0; i < 4; i++) {
    code += chars[Math.floor(Math.random() * chars.length)]
  }

  // 生成 SVG
  const svg = `
    <svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
      <rect width="100%" height="100%" fill="#f0f0f0"/>
      ${code
        .split('')
        .map(
          (char, i) => `
        <text 
          x="${padding + i * charSpacing}" 
          y="${verticalOffset}"
          fill="rgb(${Math.random() * 100},${Math.random() * 100},${Math.random() * 100})"
          font-family="Arial"
          font-size="24"
          transform="rotate(${(Math.random() - 0.5) * 30}, ${padding + i * charSpacing}, ${verticalOffset})"
        >${char}</text>
      `
        )
        .join('')}
      ${[...Array(3)]
        .map(
          () => `
        <line 
          x1="${Math.random() * width}" 
          y1="${Math.random() * height}"
          x2="${Math.random() * width}"
          y2="${Math.random() * height}"
          stroke="rgb(${Math.random() * 200},${Math.random() * 200},${Math.random() * 200})"
        />
      `
        )
        .join('')}
    </svg>
  `

  return {
    code,
    svg
  }
}
